home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Monster Media 1996 #15
/
Monster Media Number 15 (Monster Media)(July 1996).ISO
/
wildcat
/
avu1r6.zip
/
VIEWCOMP.WCC
< prev
next >
Wrap
Text File
|
1996-05-27
|
28KB
|
605 lines
'AVU - Archive View Utility
'
'Written by Peter Garner, Mildew Hall OS/2. Tel: +44-(0)1420-543542
'Email Sysop@mildewh.dircon.co.uk
'
'This source code is released into the public domain.
'
'>>If you recompile this file, you will get an "error opening input file":
'>>it won't find MILDEWH.WCC - this is my own info file, and just contains
'>>info about my system. It won't affect the program operation at all. See
'>>the source comments.
'
'Also, remember that ALL the UNZIP parameters are case sensitive! Be warned!
'
'Note: all long lines are split to be readable without scrolling
'
'-------------------------------------------------------------------------
'$INCLUDE "colours.wcc"
declare sub DeleteWorkFiles
declare sub DisplayZipList (workfil2 as string)
dim rc as integer 'general purpose result code
dim ch as integer 'general purpose character store
dim viewit as integer 'file (number) to view
dim filecounter as integer 'number of files found in Zip..
dim ZipFileCnt as integer 'each file passed thru parseline
dim counter as integer '(re)settable counter
dim fileareanum as integer 'area defined in Makewild for downloading
dim FileToExtrAndDl as integer 'file (number) to extract and download
dim MaxDisplayByteCount as long 'maximum number of displayable bytes
dim WCXversion as string 'the version of this WCX
dim InputZipFile as string 'file name to process
dim DisplayZipName as string 'file name with path stripped off
dim workdir as string 'where to put zip lists etc
dim workfil1 as string
dim workfil2 as string
dim workfil3 as string
dim ZipEntry as string 'File in a ZIP
dim dlprofiles as string 'SecProfiles allowed to download
dim configfile as string 'configuration file name and extension
dim filename as string 'name of file within Zip
dim filextension as string 'extension of file within Zip
dim filecolour as string 'colour of display line - dim if not text..
dim Zsizeorig as string 'original filesize reported by unzip
dim Zcompmeth as string 'compression method reported by unzip
dim Zsizenow as string 'compressed size of file reported by unzip
dim Zpercent as string 'percentage compression reported by unzip
dim Zfiledate as string 'filedate reported by unzip
dim Zfiletime as string 'filetime reported by unzip
dim testkey as string * 6 'reserved for future use
dim xnode as string * 3 'current node number as a string
dim viewit_S as string * 3 'caller menu choice - ascii value
dim viewittype as string * 1 '"L"etter or "N"umber - caller menu choice
dim filenumber as string * 3 'number of file displayed to caller
dim controlz as string * 1 'DOS EOF character x'1a'
dim controlzmsg as string * 35 'holds the "display limit reached" message
dim filetoview(500) as string 'number of possible files in Zip
dim limit as boolean 'is there a byte view limit ?
dim DisplayLimitReached as boolean 'has it been reached ?
dim dlenabled as boolean 'are downloads enabled ?
dim dlok as boolean '(all) download conditions met
dim filepass as boolean 'downloads password protected ?
dim ZipAsEXE as boolean 'true if ZIP stored as EXE file..
dim fRec as filerecord 'File Record definition
'─ definitions ────────────────────────────────────────────────────────────────
InputZipFile = Paramstr(1) 'First get our filename and path
controlz = chr$(&h1a) 'define the DOS EOF character
'and the message to be displayed if the
'display limit has been reached..
'
controlzmsg = chr$(7) + chr$(13) + chr$(13) + chr$(10) + magenta + \
">File Display limit reached!"
'
configfile = ".\viewcomp.cfg" 'name of config file in current directory
limit = false 'no display limits (yet)
xnode = trim$(str$(node)) 'current node number as a string
WCXversion = "1.6" 'application version
if exists(configfile) then 'test for config file..
open configfile for input as #1
input #1, MaxDisplayByteCount
input #1, fileareanum
input #1, filepass
input #1, dlprofiles
dlprofiles = ucase$(dlprofiles) 'maybe WC does this already ??
close #1
end if
if MaxDisplayByteCount > 0 then 'tests if display limit exists
limit = true
else
limit = false
end if
if fileareanum < 1 then 'if no file area number allocated
dlenabled = false 'for downloads then don't allow them
else
dlenabled = true
end if
'we'll only allow downloads if there
'are some security levels!
if instr( dlprofiles, ucase$(user.seclevel)) then
dlok = true
else
if dlprofiles = "*" then 'all users can download
dlok = true
else
if dlprofiles = "" then 'no users can download
dlok = false
end if
end if
end if
gosub TruncateTrailingSlash 'now strip off the path name that WC
'adds to our file-to-view: don't want
'callers seeing that!
'this next bit is a crude way of
'ensuring we only process ZIP or TXT files
if right$(InputZipFile, 3) = "ZIP" then
print "Opening ";green;DisplayZipName;cyan;".. please wait a moment"
else
if right$(InputZipFile, 3) = "EXE" then
print "Testing ";green;DisplayZipName;cyan;" for ZIP.. please wait a moment"
else
if right$(InputZipFile, 3) = "TXT" then
rc = displaytextfile(InputZipFile)
end
else
beep
print "Sorry - This version can only handle .ZIP, some .EXE and .TXT" \
" files at the moment"
end
end if
end if
end if
'now let's find a work area..
if environ("AVU") = "" then 'hmm.. no SET AVU=whatever, so
workdir = environ("TEMP") 'let's use TEMP instead..
else
workdir = environ("AVU") 'otherwise use the AVU path
end if
if right$(workdir, 1) <> "\" then 'bung a trailing slash on the end of
workdir = workdir + "\" 'our work directory..
end if
'define some workfiles..
'this holds the list of the zip contents
'as a plain old list of files
workfil1 = workdir + "view" + xnode + ".tmp"
'this holds the above plus headings etc
workfil2 = workdir + "view" + xnode + ".tm2"
'holds the content of the file(s) we wish
'to view
workfil3 = workdir + "view" + xnode + ".tm3"
if right$(InputZipFile, 3) = "EXE" then
gosub TestExeForZip
if ZipAsExe = false then
beep
print white
print "Sorry - no ZIP archive found in this EXE file.";yellow
end
end if
end if
gosub UnzipToCreateFileList 'now lets unzip our file..
open workfil1 for input as #1 'this is where the output went
open workfil2 for output as #2 'now we'll add some headings etc..
'but we don't want ALL the fields..
print #2, cyan;"Archive View ";yellow;WCXversion; \
white;" ";chr$(254);magenta;" File ";green;DisplayZipName
print #2, yellow
print #2, "File File Size File Creation Path / "
print #2, "No. Original.....Now Date......Time Filename"
print #2, ""
counter = 5 'set up initial counter value
'if the LOF value of the file list is 0,
'then UNZIP couldn't create it, so it
'must be corrupt..
if lof(1) = 0 then
beep
print
print green;DisplayZipName;white;" is corrupt and has been moved offline"
print
print cyan;Makewild.SysopName;" has been notified.."
print
activitylog ">>> WARNING FROM AVU: " + InputZipFile + " is corrupt!"
reset
gosub TakeFileOffline 'so flag it as offline
call Deleteworkfiles 'delete work files
end 'and end the program
end if
'now read the records in our input file:
'if the last character is a "/" then we
'don't want it, as this is the way UNZIP
'shows a directory within the zip, and we
'can't display that! Otherwise, we'll
'parse the line and extract the fields we
'want..
while not eof(1)
input #1, ZipEntry
if right$(ZipEntry, 1) <> "/" then gosub ParseLine
wend
reset 'Done! Now close all open files
call DisplayZipList (workfil2) 'and display our nicely formatted filelist
print
do
print
print yellow;
if filecounter > 0 then 'if we have some displayable files..
DisplayLimitReached = false 'set up the flag ready...
do
'ask caller for number of file to view..
print yellow+"Enter number of file to view: "+ \
green+"1 - "+str$(filecounter)+yellow+" '"+white+"Q"+yellow+ \
"' to quit";
'and if they can download, tell 'em about
'the option..
if dlok then print " or '"+white+"D"+yellow+"' to download: ";
'we have to allow letters as well as
'numbers, so use an alphanumeric mask
viewit_S = inputmask("", "XXX") 'so expect a string
'
viewit = val(viewit_S) 'also store as a number
if viewit = 0 then 'if we get a '0', it's a
viewittype = "L" '(L)etter!
viewit = asc(viewit_S) 'store the ascii value
gosub TestAlpha 'and decide what to do with it!
else
viewittype = "N" 'otherwise, it's a number
viewit = viewit 'see!
'if it's not an "ENTER", and
'it's LE the maximum number of
'files listed, it must be valid
'so exit from the loop
if (viewit >= 0 and viewit <= filecounter) then
exit do
end if
end if 'otherwise just beep, and
beep 'make the caller do it again
loop
else 'otherwise, IMHO, there were no
'displayable files found, so
beep 'tell the caller!
print yellow+"There are no viewable files in this archive! Press '"+ \
cyan+"0"+yellow+"' to quit ";
viewit = inputnumber("", 0, 0) 'I'll only take a zero now!
call DeleteworkFiles 'delete work files
end 'and exit program
end if
'
if viewittype = "N" then 'ok, we got a number, so
'lets get the file.. we'll
'stick it in our 3rd work file
print "Fetching ";green;filetoview(viewit);cyan;".. please wait a moment"
shell "unzip -cqqaa " + InputZipFile + " " + filetoview(viewit) + \
" > " + workfil3
cls
if limit then gosub LimitCheck 'if sysop has set a display
'limit let's see if our view-
'-able file is too big..
'
print cyan;"Displaying ";yellow;filetoview(viewit);white;" from "; \
green;DisplayZipName;white;" ";
if DisplayLimitReached then 'if we hit the limit, tell
'the caller before he starts
'viewing..
print grey;"(Up to ";MaxDisplayByteCount;" bytes)";white
print
else
print
end if
print
rc = displaytextfile(workfil3) 'and now, display it.
if not DisplayLimitReached then 'we've finished, so tell the
print 'caller...
print magenta;chr$(254);" End of file ";chr$(254)
end if
waitenter
call DisplayZipList (workfil2) 'and redisplay the zip file
'list
end if
'
loop
end 'here for safety !
'─────────────────────────────────────────────────────────────────────────
ParseLine: 'if filename is valid, extract required fields
ZipFileCnt = ZipFileCnt + 1 'increment file count
Zsizeorig = mid(ZipEntry, 1, 7)
Zsizenow = mid(ZipEntry, 17, 7)
Zfiledate = mid(ZipEntry, 31, 8)
Zfiletime = mid(ZipEntry, 41, 5)
filename = mid(ZipEntry,59,(len(ZipEntry)-58)) 'get the file name
filextension = ucase$(right$(filename, 4)) 'and the extension
if right$(filextension, 1) <> "/" then 'ignore directory names..
'crude bit number 2..
'here's a list of file extensions that are non-text. The problem is that
'if i have to open each file, and read a few characters to try and determine
'if the files are binary or not, then this will impose a large overhead that
'may affect the system adversely. This is why this application will not
'replace Dataview, or similar software (yet). You can add others that may
'come across - don't know if there's an upper limit to select case..
'Really, there's no reason why you -shouldn't- display these files - the
'utility won't mind, it's just that strange things may happen on the screen.
'It's up to you..
select case filextension
'ignore all these..
case ".EXE", ".COM", ".BIN", ".SYS", ".ZIP", ".PAK", ".LHA", ".ARJ", \
".RAR", ".ARC", ".DLL", ".BMP", ".ICO", ".JPG", ".HLP", ".INI", \
".UC2", ".HAP", ".OVL", ".OVR", ".SVP", ".VBX", ".OCX", ".FRX", \
".WCX", ".PCX", ".GIF", ".WAV"
filecolour = grey
print #2, white;"["grey;" - ";white;"] ";grey;
case else
filecolour = white
filecounter = filecounter + 1
filenumber = right$((" " + str$(filecounter)), 3)
print #2, white;"["cyan;filenumber;white;"] ";green;
filetoview (filecounter) = filename
end select
end if
print #2,Zsizeorig;" ";
print #2,Zsizenow;" ";cyan;
print #2,Zfiledate;" ";
print #2,Zfiletime;" ";filecolour;
print #2,filename
if ZipFileCnt > counter then 'this bit displays a "." every
print "."; 'five filenames parsed just so
counter = counter + 5 'the caller knows it's still
end if 'working! Useful if your disk is
'slow.
return
'─────────────────────────────────────────────────────────────────────────
sub DisplayZipList (workfil2 as string) 'simply clear the screen and
cls 'display the list of files in
rc = displaytextfile(workfil2) 'the archive
end sub
'─────────────────────────────────────────────────────────────────────────
TakeFileOffline: 'take a (corrupt) file offline
'
if Getfileinfo(fRec, DisplayZipName) then
fRec.flags = &H020 'means "offline"
fRec.keywords(6) = "CORRUPT!" 'change 6th keyword
Updatefile(fRec) 'update filebase record
activitylog ">>> MESSAGE FROM AVU: moved " + InputZipFile + " offline!"
else
activitylog ">>> WARNING FROM AVU: unable to move " + InputZipFile + \
" offline!"
end if
'
return
'─────────────────────────────────────────────────────────────────────────
Sub DeleteWorkFiles 'delete workfiles if they exist
if exists(workfil1) then kill workfil1
if exists(workfil2) then kill workfil2
if exists(workfil3) then kill workfil3
end sub
'─────────────────────────────────────────────────────────────────────────
Limitcheck: 'check to see if the file is
'too big to display all..
'the file is opened in binary
'mode. if it's too big, a DOS
'EOF character is written at
'specified limit position, then
'rewind the number of bytes in
'the warning msg, and write the
'msg! If you change the message,
'don't forget to change the msg
'length variable!
'I'm really chuffed with this bit - it shows just how useful DOS can be
'be, and it saves loadsa file i/o!
open workfil3 for binary as #1
if lof(1) > MaxDisplayByteCount then
put #1, (MaxDisplayByteCount - len(controlzmsg)), controlzmsg
put #1, MaxDisplayByteCount, controlz
DisplayLimitReached = true
end if
close #1
return
'─────────────────────────────────────────────────────────────────────────
TestAlpha: 'here's where our (L)etter
'options are handled..
if viewittype = "L" then
select case viewit
case 48, 81, 113 ' 0/Q/q - quit
call DeleteworkFiles
end
case 68, 100 'D/d - download a file
'
if dlenabled then 'are we okay to go ??
if dlok then
FileToExtrAndDl = inputnumber("Download which file #:"+\
green+"0, 1 - " + str$(filecounter)+yellow+" ",\
0 , filecounter)
'we can abort by typing '0'
'so just display the ZIP list
if FileToExtrAndDl = 0 then
call DisplayZipList (workfil2)
return
end if
'if there's a path, we can't
'handle it yet, so fudge it
'for now. Might be okay to
'make up a filename on the fly..
if instr(filetoview(FileToExtrAndDl), "/") then
beep
print cyan;"Sorry! Can't (yet) extract files with pathnames.."
print "Turn screen capture on and use view (";white;FileToExtrAndDl;cyan;")instead";white
waitenter
else 'ok, extract it to our temporary
'file area - remember that ?
shell "unzip -qoj " + InputZipFile + " " + \
filetoview(FileToExtrAndDl) + " -d " + \
workdir
'now find the file size:good old
'binary mode again!)
open workdir+filetoview(FileToExtrAndDl) for binary as #1
frec.size = lof(1) 'update WC field
close #1
'update other WC fields
fRec.name = filetoview(FileToExtrAndDl)
fRec.StoredPath = workdir
fRec.area = fileareanum
fRec.description = green + "File for " + cyan + \
user.name + \
green + " extracted from "+ \
magenta + \
DisplayZipName
'if we specified password mode,
'then add one now - use the
'caller's login password!
if filepass then fRec.password = user.password
'Give AVU the upload credit..
fRec.uploader = "AVU"
fRec.keywords(1) = "AVU"
'This section updates or adds the
'file we just extracted to the
'files database, ready for d/ld.
if addfile(fRec) then
activitylog "Extracted " + filetoview(FileToExtrAndDl) + \
" for download (new)"
if Getfileinfo(fRec, filetoview(FileToExtrAndDl)) then
Updatefile(fRec)
beep
print
gosub FileReadyMsg 'Tell caller file is ready
end if
else
activitylog "Extracted " + filetoview(FileToExtrAndDl) + \
" for download (update)"
beep
gosub FileReadyMsg 'Tell caller file is ready
end if
end if
return
'
end if
else
beep 'no download area assigned..
print "Sorry: ";Makewild.SysopName;" has not " \
"configured a download area.."
waitenter
end if
'this whole section can be deleted if desired, or you can
'put your own advertising in.
'If you aren't compiling it at Mildew Hall, you should
'comment out the '$INCLUDE anyway..
'-----------------8< snip ----------------------------------
case 33 '! - exclamation'
cls
print white;
print "AVU - A freeware archive view utility for Wildcat"
'$INCLUDE "\wc411\wcc\common\mildewh.wcc"
waitenter
call DisplayZipList(workfil2)'back to displaying the list
return
'-----------------8< snip ----------------------------------
case 63, 72, 104 '?, h, H
print
print cyan;"(";yellow;"h";cyan;")";green;"elp ";
print cyan;"(";yellow;"q";cyan;")";magenta;"uit ";
if dlenabled then if dlok then
print cyan;"(";yellow;"d";cyan;")";white;"ownload ";\
"extracted file from file area ";\
green;fileareanum
end if
print
'for your average caller any
'other key is a mistake. If it's
'node 0, I left it in just for
'testing in case I wanted to
'add any more keys..
case else
if xnode = "0" then print viewit
beep
end select
end if
return
'─────────────────────────────────────────────────────────────────────────
FileReadyMsg: 'tells caller their file is ready
print green;fRec.name;white;" is ready to download from area ";cyan;\
fileareanum;white;
'if we're using passwords, tell
'caller the password - it's
'their own anyway!
if filepass then print " (Password is ";green;user.password;white;")";
'
print yellow
print
waitenter
return
'─────────────────────────────────────────────────────────────────────────
TruncateTrailingSlash: 'steps backwards through the path+filename until the
'first "\" to get the filename alone.
for ch = len(InputZipFile) to 1 step -1
if mid(InputZipFile, ch, 1) = "\" then
DisplayZipName = mid(InputZipFile, (ch+1), (len(InputZipFile) - ch))
exit for
end if
next ch
return
'─────────────────────────────────────────────────────────────────────────
UnzipToCreateFileList: 'UNZIP creates a filelist. The freeware unzip
'parameter -qq means 'very quiet' so just the file
'details and nothing else are displayed...
shell "unzip -vqq " + InputZipFile + " > " + workfil1
return
'─────────────────────────────────────────────────────────────────────────
TestExeForZip: 'see if we have a ZIP lurking in this EXE file ..
ZipAsExe = false 'set the flag first..
'and check the header
shell "unzip -Zh " + InputZipFile + " > " + workfil1
open workfil1 for binary as #1
if lof(1) = 0 then 'nothing created, so it's
ZipAsExe = false 'not a ZIP file, so delete
close #1 'the temporary file..
kill workfil1
else
close #1 'got one - example below
kill workfil1
ZipAsExe = true 'Archive: area_88/WINZIP95.EXE 497993 bytes 19 files
end if
return
'
'End of source code for version 1.6